<template>
	<view class="ext-user">
		<view class="team-cate">
			<view class="head_view"
				:style="{backgroundImage:`url(${$util.img('public/uniapp/h5/fenxiao/bgm_performance_center.png')})`}">
				<view class="head_item">
					<view class="head_t">{{regMemberNum}}</view>
					<view class="head_c">累计注册粉丝</view>
				</view>
				<view class="head_item">
					<view class="head_t">{{payMemberNum}}</view>
					<view class="head_c">累计支付粉丝</view>
				</view>
			</view>
			<view class="cate-body">
				<view  v-for="(item, index) in category" :key="index" class="cate-li" :class="{ 'active color-base-text color-base-border': type == item.type }" @click="selectCate(item.type)">
					{{item.name}}
				</view>
			</view>
		</view>
		<mescroll-uni ref="mescroll" @getData="getData" :size="20" top="430">
			<block slot="list">
				<view class="extension-user">
					<view class="user" v-if="extensionList.length > 0" v-for="(itmes,index) in extensionList" :key="index">
						<image class="user-avatar" :src="itmes.headimg ? $util.img(itmes.headimg) : $util.getDefaultImage().default_headimg" mode="aspectFit"></image>
						<view class="">
							<view class="user-name">{{itmes.nickname | itmes.mobile}}</view>
							<view class="user-text">锁粉时间：{{itmes.reg_time}}</view>
						</view>
					</view>
				</view>
				<ns-empty v-if="!extensionList.length && showEmpty" text="暂无推广用户息" :isIndex="!1" :fixed="!1"></ns-empty>
			</block>			
		</mescroll-uni>
		<loading-cover ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
	import globalConfig from '@/common/js/golbalConfig.js';
	export default {
		data() {
			return {
				category: [
					{
						type: 0,
						name: '注册粉丝'
					},
					{
						type: 1,
						name: '支付粉丝'
					}
				],
				type: 0,
				extensionList: {},
				showEmpty: false,
				regMemberNum: 0,
				payMemberNum: 0
			};
		},
		onShow() {
			this.$langConfig.refresh();	
			uni.setNavigationBarTitle({
				title:'店铺粉丝'
			})
			if (!uni.getStorageSync('token')) {
				this.$util.redirectTo(
					'/otherpages/login/login/login',
					{
						back: '/otherpages/promotion/extension-user'
					},
					'redirectTo'
				);
			}
			this.getMemberSum();
		},
		mixins: [globalConfig],
		methods: {
			selectCate(e) {
				this.type = e;
				this.$refs.mescroll.refresh();
			},
			getMemberSum() {
				this.$api.sendRequest({
					url: '/fenxiao/api/shop/spreadUserSum',
					data: {},
					success: res => {
						if (res.code == 0) {
							this.regMemberNum =  res.data.regMemberNum;
							this.payMemberNum =  res.data.payMemberNum;
						}
					}
				});
			},
			getData(mescroll) {
				if (mescroll.num == 1) {
					this.extensionList = [];
				}
				this.showEmpty = false;
				this.$api.sendRequest({
					url: '/fenxiao/api/shop/spreadUser',
					data: {
						type:this.type,
						page: mescroll.num,
						page_size: mescroll.size
					},
					success: res => {
						this.showEmpty = true;
						let newArr = [];
						let msg = res.message;
						if (res.code == 0 && res.data && res.data.list) {
							newArr = res.data.list;
							newArr.forEach(v => {
								v.reg_time = this.$util.timeStampTurnTime(v.reg_time).substring(0, 19);
							});
						} else {
							this.$util.showToast({
								title: msg
							});
						}
						mescroll.endSuccess(newArr.length);
						//设置列表数据
						if (mescroll.num == 1) this.extensionList = []; //如果是第一页需手动制空列表
						this.extensionList = this.extensionList.concat(newArr); //追加新数据
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					fail: res => {
						this.showEmpty = true;
						mescroll.endErr();
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	%flex {
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.ext-user {
		background-color: #f8f8f8;
	}
	.team-cate {
		width: calc(100%);
		height: 420rpx;		
		position: fixed;
		left: 0;
		top: var(--window-top);
		
		.head_view {
			position: relative;
			margin: 24rpx 32rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			height: 280rpx;
			width: 686rpx;
			background-repeat: no-repeat;
			background-size: 100% 100%;
		
			.head_item {
				width: 49%;
				height: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
		
				.head_t {
					font-size: 36rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					line-height: 50rpx;
				}
		
				.head_c {
					font-size: 24rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					line-height: 33rpx;
		
				}
			}
		
			.head_line {
				width: 1rpx;
				height: 42rpx;
				background: #FFFFFF;
			}
		}
		
		.cate-body {
			height: 90rpx;
			display: flex;
			box-sizing: border-box;
			background: #ffffff;
			.cate-li {
				flex: 1;
				display: flex;
				justify-content: center;
				align-items: center;
				line-height: 90rpx;
				height: 100%;
				font-size: 30rpx;
				
				&.active {
					box-sizing: border-box;
					border-bottom: 4rpx solid;
				}
			}
		}
		
	}
	.extension-user {
		padding: 0 30rpx;
		background-color: #fff;
		// min-height: 100vh;
	}	
	.user {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		padding: 40rpx 0;
		border-bottom: 1rpx solid #E8E8E8;

		.user-avatar {
			margin-right: 20rpx;
			width: 88rpx;
			height: 88rpx;
			border: 1rpx solid #ebebeb;
			border-radius: 44rpx;
		}

		.user-name {
			font-size: 32rpx;
			color: #000000;
			line-height: 45rpx;
		}

		.user-text {
			margin-top: 16rpx;
			font-size: 24rpx;
			color: #909399;
			line-height: 34rpx;
		}
	}
</style>
